package com.controller;

import com.po.PermissionResourcePO;
import com.po.PlacedHospitalPO;
import com.result.Result;
import com.service.PermissionResourceService;
import com.service.PlacedHospitalService;
import com.utils.Tree;
import com.vo.PermissionResourceVO;
import com.vo.PlacedHospitalVO;
import com.vo.ResourceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: chihaojie
 * @Date: 2019/5/29 16:17
 * @Version 1.0
 * @Note
 */

@Api(value = "permissionResourceApi")
@CrossOrigin
@RestController
@RequestMapping("/permissionResource")
public class PermissionResourceController {


    @Autowired
    private PermissionResourceService permissionResourceService;

    @ApiOperation(value = "新增资源", httpMethod = "POST", notes = "新增资源")
    @RequestMapping(value = "/add", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Result<PermissionResourceVO> save(@RequestBody PermissionResourcePO permissionResourcePO) {
        return new Result<PermissionResourceVO>().ok(permissionResourceService.save(permissionResourcePO));
    }

    @ApiOperation(value = "修改资源", httpMethod = "POST", notes = "修改")
    @RequestMapping(value = "/edit", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
    public Result<PermissionResourceVO> edit(@RequestBody PermissionResourcePO permissionResourcePO) {
        return new Result<PermissionResourceVO>().ok(permissionResourceService.edit(permissionResourcePO));
    }


    @ApiOperation(value = "remove", httpMethod = "GET", notes = "删除资源")
    @RequestMapping(value = "/remove", method = RequestMethod.GET)
    public Result remove(@RequestParam("id") Long  id) {
        return new Result().ok(permissionResourceService.remove(id));
    }


    /**
     * 获取顶级目录
     */
    @ApiOperation(value = "获取顶级资源目录", httpMethod = "GET", notes = "获取顶级资源目录")
    @RequestMapping(value = "/getTopResourceNodeList", method = RequestMethod.GET)
    public Result<List<ResourceVO>> getTopResourceNodeList() {
        return new Result<List<ResourceVO>>().ok(permissionResourceService.getTopResourceNodeList());
    }

    /**
     * 根据父级获取子级树
     */
    @ApiOperation(value = "根据父级获取子级资源树", httpMethod = "GET", notes = "根据父级获取子级资源树")
    @RequestMapping(value = "/getSubResourceNodeList", method = RequestMethod.GET)
    public Result<List<ResourceVO>> getSubResourceNodeList(@RequestParam String resourceId) {
        return new Result<List<ResourceVO>>().ok(permissionResourceService.getSubResourceNodeList(resourceId));
    }

    /**
     * 获取资源树
     *
     */
    @ApiOperation(value = "资源树", httpMethod = "GET", notes = "获取资源树")
    @RequestMapping(value = "/tree", method = RequestMethod.GET)
    public Result<List<Tree<ResourceVO>>> treeByResourceId() {
        return new Result<List<Tree<ResourceVO>>>().ok(permissionResourceService.treeResource());
    }

}
